#include<stdio.h>
#include<signal.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>

void sig_int(int signo);

volatile sig_atomic_t  quitflag;

int main(int argc,char **argv)
{
	sigset_t           newmask,oldmask,zeromask;

	if(signal(SIGINT,sig_int) == SIG_ERR)
		printf("signal(SIGINT) error\n");
	if(signal(SIGQUIT,sig_int) ==SIG_ERR)
		printf("signal(SIGQUIT) error\n");

	sigemptyset(&zeromask);
	sigemptyset(&newmask);
	sigaddset(&newmask,SIGQUIT);

	if(sigprocmask(SIG_BLOCK,&newmask,&oldmask) < 0)
		printf("SIG_BLOCK error\n");

	while(quitflag ==0)
		sigsuspend(&zeromask);
	
	quitflag = 0;

	if(sigprocmask(SIG_SETMASK,&oldmask,NULL) < 0)
		printf("SIG_SETMASK error\n");

	exit(0);
}

void sig_int(int signo)
{
	if(signo == SIGINT)
		printf("\ninterrupt\n");
	if(signo == SIGQUIT)
		quitflag = 1;
}
